home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / cvs-1.11.1 / contrib / sccs2rcs < prev   
Text File  |  2001-01-01  |  8KB  |  282 lines

  1. #! /usr/bin/csh -f
  2. #
  3. # Sccs2rcs is a script to convert an existing SCCS
  4. # history into an RCS history without losing any of
  5. # the information contained therein.
  6. # It has been tested under the following OS's:
  7. #     SunOS 3.5, 4.0.3, 4.1
  8. #     Ultrix-32 2.0, 3.1
  9. #
  10. # Things to note:
  11. #   + It will NOT delete or alter your ./SCCS history under any circumstances.
  12. #
  13. #   + Run in a directory where ./SCCS exists and where you can
  14. #       create ./RCS
  15. #
  16. #   + /usr/local/bin is put in front of the default path.
  17. #     (SCCS under Ultrix is set-uid sccs, bad bad bad, so
  18. #     /usr/local/bin/sccs here fixes that)
  19. #
  20. #   + Date, time, author, comments, branches, are all preserved.
  21. #
  22. #   + If a command fails somewhere in the middle, it bombs with
  23. #     a message -- remove what it's done so far and try again.
  24. #         "rm -rf RCS; sccs unedit `sccs tell`; sccs clean"
  25. #     There is no recovery and exit is far from graceful.
  26. #     If a particular module is hanging you up, consider
  27. #     doing it separately; move it from the current area so that
  28. #     the next run will have a better chance or working.
  29. #     Also (for the brave only) you might consider hacking
  30. #     the s-file for simpler problems:  I've successfully changed
  31. #     the date of a delta to be in sync, then run "sccs admin -z"
  32. #     on the thing.
  33. #
  34. #   + After everything finishes, ./SCCS will be moved to ./old-SCCS.
  35. #
  36. # This file may be copied, processed, hacked, mutilated, and
  37. # even destroyed as long as you don't tell anyone you wrote it.
  38. #
  39. # Ken Cox
  40. # Viewlogic Systems, Inc.
  41. # kenstir@viewlogic.com
  42. # ...!harvard!cg-atla!viewlog!kenstir
  43. #
  44. # Various hacks made by Brian Berliner before inclusion in CVS contrib area.
  45.  
  46.  
  47. #we'll assume the user set up the path correctly
  48. # for the Pmax, /usr/ucb/sccs is suid sccs, what a pain
  49. #   /usr/local/bin/sccs should override /usr/ucb/sccs there
  50. set path = (/usr/local/bin $path)
  51.  
  52.  
  53. ############################################################
  54. # Error checking
  55. #
  56. if (! -w .) then
  57.     echo "Error: ./ not writeable by you."
  58.     exit 1
  59. endif
  60. if (! -d SCCS) then
  61.     echo "Error: ./SCCS directory not found."
  62.     exit 1
  63. endif
  64. set edits = (`sccs tell`)
  65. if ($#edits) then
  66.     echo "Error: $#edits file(s) out for edit...clean up before converting."
  67.     exit 1
  68. endif
  69. if (-d RCS) then
  70.     echo "Warning: RCS directory exists"
  71.     if (`ls -a RCS | wc -l` > 2) then
  72.         echo "Error: RCS directory not empty
  73.         exit 1
  74.     endif
  75. else
  76.     mkdir RCS
  77. endif
  78.  
  79. sccs clean
  80.  
  81. set logfile = /tmp/sccs2rcs_$$_log
  82. rm -f $logfile
  83. set tmpfile = /tmp/sccs2rcs_$$_tmp
  84. rm -f $tmpfile
  85. set emptyfile = /tmp/sccs2rcs_$$_empty
  86. echo -n "" > $emptyfile
  87. set initialfile = /tmp/sccs2rcs_$$_init
  88. echo "Initial revision" > $initialfile
  89. set sedfile = /tmp/sccs2rcs_$$_sed
  90. rm -f $sedfile
  91. set revfile = /tmp/sccs2rcs_$$_rev
  92. rm -f $revfile
  93.  
  94. # the quotes surround the dollar signs to fool RCS when I check in this script
  95. set sccs_keywords = (\
  96.     '%W%[     ]*%G%'\
  97.     '%W%[     ]*%E%'\
  98.     '%W%'\
  99.     '%Z%%M%[     ]*%I%[     ]*%G%'\
  100.     '%Z%%M%[     ]*%I%[     ]*%E%'\
  101.     '%M%[     ]*%I%[     ]*%G%'\
  102.     '%M%[     ]*%I%[     ]*%E%'\
  103.     '%M%'\
  104.     '%I%'\
  105.     '%G%'\
  106.     '%E%'\
  107.     '%U%')
  108. set rcs_keywords = (\
  109.     '$'Id'$'\
  110.     '$'Id'$'\
  111.     '$'Id'$'\
  112.     '$'SunId'$'\
  113.     '$'SunId'$'\
  114.     '$'Id'$'\
  115.     '$'Id'$'\
  116.     '$'RCSfile'$'\
  117.     '$'Revision'$'\
  118.     '$'Date'$'\
  119.     '$'Date'$'\
  120.     '')
  121.  
  122.  
  123. ############################################################
  124. # Get some answers from user
  125. #
  126. echo ""
  127. echo "Do you want to be prompted for a description of each"
  128. echo "file as it is checked in to RCS initially?"
  129. echo -n "(y=prompt for description, n=null description) [y] ?"
  130. set ans = $<
  131. if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
  132.     set nodesc = 0
  133. else
  134.     set nodesc = 1
  135. endif
  136. echo ""
  137. echo "The default keyword substitutions are as follows and are"
  138. echo "applied in the order specified:"
  139. set i = 1
  140. while ($i <= $#sccs_keywords)
  141. #    echo '    '\"$sccs_keywords[$i]\"'    ==>    '\"$rcs_keywords[$i]\"
  142.     echo "    $sccs_keywords[$i]    ==>    $rcs_keywords[$i]"
  143.     @ i = $i + 1
  144. end
  145. echo ""
  146. echo -n "Do you want to change them [n] ?"
  147. set ans = $<
  148. if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then
  149.     echo "You can't always get what you want."
  150.     echo "Edit this script file and change the variables:"
  151.     echo '    $sccs_keywords'
  152.     echo '    $rcs_keywords'
  153. else
  154.     echo "good idea."
  155. endif
  156.  
  157. # create the sed script
  158. set i = 1
  159. while ($i <= $#sccs_keywords)
  160.     echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
  161.     @ i = $i + 1
  162. end
  163.  
  164. onintr ERROR
  165.  
  166. ############################################################
  167. # Loop over every s-file in SCCS dir
  168. #
  169. foreach sfile (SCCS/s.*)
  170.     # get rid of the "s." at the beginning of the name
  171.     set file = `echo $sfile:t | sed -e "s/^..//"`
  172.  
  173.     # work on each rev of that file in ascending order
  174.     set firsttime = 1
  175.     sccs prs $file | grep "^D " | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
  176.     foreach rev (`cat $revfile`)
  177.         if ($status != 0) goto ERROR
  178.  
  179.         # get file into current dir and get stats
  180.     set year = `echo $date | cut -c3-4`
  181.     if ($year < 70) then
  182.         # Y2K Bug, change century to 20
  183.         set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("20%s %s", $3, $4); exit}'`
  184.     else
  185.         set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("19%s %s", $3, $4); exit}'`
  186.     endif
  187.         set author = `sccs prs -r$rev $file | grep "^D " | awk '{print $5; exit}'`
  188.         echo ""
  189.         echo "==> file $file, rev=$rev, date=$date, author=$author"
  190.         sccs edit -r$rev $file >>& $logfile
  191.         if ($status != 0) goto ERROR
  192.         echo checked out of SCCS
  193.  
  194.         # add RCS keywords in place of SCCS keywords
  195.         sed -f $sedfile $file > $tmpfile
  196.         if ($status != 0) goto ERROR
  197.         echo performed keyword substitutions
  198.         cp $tmpfile $file
  199.  
  200.         # check file into RCS
  201.         if ($firsttime) then
  202.             set firsttime = 0
  203.             if ($nodesc) then
  204.         echo about to do ci
  205.                 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 
  206.                 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile
  207.                 if ($status != 0) goto ERROR
  208.                 echo initial rev checked into RCS without description
  209.             else
  210.                 echo ""
  211.                 echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
  212.                 cat > $tmpfile
  213.                 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile
  214.                 if ($status != 0) goto ERROR
  215.                 echo initial rev checked into RCS
  216.             endif
  217.         else
  218.             # get RCS lock
  219.         set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'`
  220.         if ("$lckrev" =~ [0-9]*.*) then
  221.         # need to lock the brach -- it is OK if the lock fails
  222.         rcs -l$lckrev $file >>& $logfile
  223.         else
  224.         # need to lock the trunk -- must succeed
  225.                 rcs -l $file >>& $logfile
  226.                 if ($status != 0) goto ERROR
  227.         endif
  228.             echo got lock
  229.             sccs prs -r$rev $file | grep "." > $tmpfile
  230.             # it's OK if grep fails here and gives status == 1
  231.             # put the delta message in $tmpfile
  232.             ed $tmpfile >>& $logfile <<EOF
  233. /COMMENTS
  234. 1,.d
  235. w
  236. q
  237. EOF
  238.             ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
  239.             if ($status != 0) goto ERROR
  240.             echo checked into RCS
  241.         endif
  242.         sccs unedit $file >>& $logfile
  243.         if ($status != 0) goto ERROR
  244.     end
  245.     rm -f $file
  246. end
  247.  
  248.  
  249. ############################################################
  250. # Clean up
  251. #
  252. echo cleaning up...
  253. mv SCCS old-SCCS
  254. rm -f $tmpfile $emptyfile $initialfile $sedfile
  255. echo ===================================================
  256. echo "       Conversion Completed Successfully"
  257. echo ""
  258. echo "         SCCS history now in old-SCCS/"
  259. echo ===================================================
  260. set exitval = 0
  261. goto cleanup
  262.  
  263. ERROR:
  264. foreach f (`sccs tell`)
  265.     sccs unedit $f
  266. end
  267. echo ""
  268. echo ""
  269. echo Danger\!  Danger\!
  270. echo Some command exited with a non-zero exit status.
  271. echo Log file exists in $logfile.
  272. echo ""
  273. echo Incomplete history in ./RCS -- remove it
  274. echo Original unchanged history in ./SCCS
  275. set exitval = 1
  276.  
  277. cleanup:
  278. # leave log file
  279. rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile
  280.  
  281. exit $exitval
  282.